/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package AWT;

import java.awt.Button;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Vallarta {

     TextArea ta=new TextArea();
     TextField tf=new TextField();
     Button b=new Button("Agregar");
     MenuBar m1=new MenuBar();

     
     public Vallarta(){

         Frame f=new Frame();
     
         f.add(ta,"North");
         f.add(b,"South");
         f.add(tf,"Center");
         f.setMenuBar(m1);
     
        ManejaBoton mb=new ManejaBoton();
        b.addActionListener(mb);

        Teclas tc=new Teclas();
        tf.addKeyListener(tc);

        CerrarVentana cv=new CerrarVentana();
        f.addWindowListener(cv);

        BotonColor bc=new BotonColor();
        b.addMouseListener(bc);

        f.setVisible(true);
        f.setSize(300,300);
   }

   class ManejaBoton implements ActionListener{
     public void actionPerformed(ActionEvent e){
        ta.append("\n"+tf.getText());
     }
   }

   class Teclas extends KeyAdapter{
       public void keyPressed(KeyEvent evt){
           if(evt.getKeyCode()==10)
               ta.append("\n"+tf.getText());
       }
   }

   class BotonColor extends MouseAdapter{
       public void mouseEntered(MouseEvent em){
       b.setBackground(Color.red);
       }
       public void mouseExited(MouseEvent evt){
           b.setBackground(Color.YELLOW);
       }
   }


   public class CerrarVentana extends WindowAdapter{
    public void windowClosing(WindowEvent e){
    System.exit(0);
    }
   }
  
    public static void main(String[] args) {
    Vallarta v=new Vallarta();
    
    }
}

